-
-
Notifications
You must be signed in to change notification settings - Fork 932
ESM build #6254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ESM build #6254
Conversation
|
I think this setup assumes a bit too much about where the worker code file is. |
|
@HarelM , i've split it out so that the worker url is set explicitly I've also added build tests to make sure the esm build is actually esm (they don't go deep though, because i.e. murmurhash.js does have |
|
This looks great! Thanks! |
|
I would recommend also to use |
|
I've tried npm pack, and loading it into maputnik node_modules, which appear to work fine. I believe it's still just using the .js version, rather than the new .mjs |
|
ngx-maplibre-gl appear to pick up the esm module in the showcase, so it'll only work if the showcase/main.ts file has the setWorkerUrl added - otherwise the map will just be the light blue background without data. import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
import * as maplibregl from 'maplibre-gl';
// Set the worker URL for MapLibre GL when using ESM version
maplibregl.setWorkerUrl('/maplibre-gl/maplibre-gl-worker.mjs');
bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
); |
|
Either we can use the auto-worker url like there was logic for previously, or this might have to come as a breaking change if the default will be an explicit setting of the worker url. Or both, having the auto-url logic now, and requiring explicit url from next major. |
|
I don't think the auto-worker url will work for angular (webpack) unfortunately. |
|
I think going ESM-only in v6 is the right call here. |
| <body> | ||
| <div id="map"></div> | ||
| <script type="module"> | ||
| import * as maplibregl from '../../dist/maplibre-gl.mjs'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will work in the docs' examples.
Can you check if a change is needed around here:
maplibre-gl-js/build/generate-docs.ts
Line 101 in 05067bd
| htmlContent = htmlContent.replace(/-dev.js/g, '.js'); |
| import {plugins, watchStagingPlugin} from './build/rollup_plugins'; | ||
| import banner from './build/banner'; | ||
| import {type RollupOptions} from 'rollup'; | ||
| import {config as cspConfig} from './rollup.config.csp'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better name to the file and method is probably needed here.
| const content = fs.readFileSync(esmPath, 'utf8'); | ||
|
|
||
| // Check for ES module exports at the end of the file | ||
| expect(content).toMatch(/export\s+\{[^}]+\};\s*$/m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super thrilled with checking the string content of the file, is there a better way to check this?
|
I would expect to see more documentation on how to use this new ESM build, one of the places is probably here: But I think there might be a need for more descriptive information, maybe some info on packagers such as webpack and rollup... |
|
|
@louwers told me so! |
|
This is on the roadmap to version 6, which is the next breaking change version, it's just not clear when we would create a breaking change version... |
|
I'm experimenting to use the ESM modules with Vite/React Router v7. If you need any feedback, just contact me. Works so far like this: import { Map, setWorkerURL } from "maplibre-gl";
import webWorkerURL from "maplibre-gl/dist/maplibre-gl-worker.mjs?url";
setWorkerUrl(webWorkerURL);
const map = new Map(...);Vite loads the CJS module when using SSR (as far as I understood because NodeJS resolution is used on the server side per default). To prevent that, one can set it up like this in export default defineConfig({
...,
ssr: {
noExternal: ['maplibre-gl'],
},
});Not sure if this is the best solution. "noExternal" might decrease module resolution performance on the server side. |
|
@chrneumann The |
|
But it will also be used with bundlers? And this needs documentation (#6254 (comment))? Anyways, maybe it's helpful for someone who wants to use the ESM build with Vite as I do :) |
Add ESM output, next to the UMD/AMD modules.
Closes #1595
Screen.Recording.2025-08-13.at.22.34.23.mov
I've converted below examlple to use the new ESM bundle
http://localhost:9966/test/examples/filter-layer-symbols-using-global-state.html
Launch Checklist